package com.itmeima.service.impl;

import com.itmeima.bean.Subway;
import com.itmeima.dao.SubwayDao;
import com.itmeima.dao.SubwayDao;
import com.itmeima.dao.impl.SubwayDaoImpl;
import com.itmeima.service.SubwayService;

import java.util.ArrayList;

public class SubwayServiceImpl implements SubwayService {
    private SubwayDao subwayDao = new SubwayDaoImpl();
    //查看
    //把地铁信息集合返回给上一层
    @Override
    public ArrayList<Subway> viewSubways() {
        return subwayDao.getList();
    }

    //判断
    @Override
    public boolean judge(String subID,String subName) {
        ArrayList<Subway> list = subwayDao.getList();
        for (Subway subway : list) {
            //  一个地铁站应该只有一个名字和一个id
            //所以会有以下4种情况
                //id重复/地铁名不重复
                //id不重复/地铁明重复
                //id重复/地铁名重复
                //id不重复/地铁名不重复
            if (subID.equals(subway.getSubID())){
                System.out.println("地铁站编号重复");
                return true;
            }else if (subName.equals(subway.getSubName())){
                System.out.println("地铁站名称重复");
                return true;
            }
        }
        //不同返回false
        return false;
    }

    //添加
    @Override
    public boolean addSubways(Subway sub) {
        return subwayDao.addSubways(sub);
    }
}
